"""
API 过滤器

用于 API 列表的筛选功能
"""

import django_filters
from pecco_site.models import Product, Category, CarouselItem, StaticPage


class ProductFilter(django_filters.FilterSet):
    """产品过滤器"""
    is_active = django_filters.BooleanFilter()
    usage = django_filters.ChoiceFilter(choices=Product.USAGE_CHOICES)
    tag_new = django_filters.BooleanFilter()
    tag_hot = django_filters.BooleanFilter()
    tag_featured = django_filters.BooleanFilter()
    category = django_filters.NumberFilter(field_name='categories__id')
    
    class Meta:
        model = Product
        fields = ['is_active', 'usage', 'tag_new', 'tag_hot', 'tag_featured', 'category']


class CategoryFilter(django_filters.FilterSet):
    """分类过滤器"""
    is_active = django_filters.BooleanFilter()
    
    class Meta:
        model = Category
        fields = ['is_active']


class CarouselFilter(django_filters.FilterSet):
    """轮播图过滤器"""
    is_active = django_filters.BooleanFilter()
    
    class Meta:
        model = CarouselItem
        fields = ['is_active']


class StaticPageFilter(django_filters.FilterSet):
    """静态页面过滤器"""
    is_active = django_filters.BooleanFilter()
    page_type = django_filters.ChoiceFilter(choices=StaticPage.PAGE_TYPES)
    
    class Meta:
        model = StaticPage
        fields = ['is_active', 'page_type']

